﻿using Aspose.Words;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Common
{
    /// <summary>
    /// 模板内容实体
    /// </summary>
    public class WordsTemp
    {
        /// <summary>
        /// 标签
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 单个文字内容或者图片内容
        /// </summary>
        public string Value { get; set; }

        private FileFormat _Type = FileFormat.String;
        public FileFormat Type
        {
            get
            {
                return _Type;
            }
            set
            {
                _Type = value;
            }
        }
    }

    /// <summary>
    /// 内容类型（目前只有文字和图片）
    /// </summary>
    public enum FileFormat
    {
        /// <summary>
        /// 文字
        /// </summary>
        String,
        /// <summary>
        /// 图片
        /// </summary>
        Image
    }

    /// <summary>
    /// 图片插入辅助类
    /// </summary>
    public class ReplaceAndInsertImage : IReplacingCallback
    {
        /// <summary>
        /// 需要插入的图片路径
        /// </summary>
        public string url { get; set; }

        public ReplaceAndInsertImage(string url)
        {
            this.url = url;
        }

        public ReplaceAction Replacing(ReplacingArgs e)
        {
            //获取当前节点
            var node = e.MatchNode;
            //获取当前文档
            Document doc = node.Document as Document;
            DocumentBuilder builder = new DocumentBuilder(doc);
            //将光标移动到指定节点
            builder.MoveTo(node);
            //插入图片
            //builder.InsertImage(url, 140, 140);
            return ReplaceAction.Replace;
        }
    }
}
